Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
Get active element in document when body contenteditable="true"

I'm testing the below in edge browser but I'm ultimately trying to get this to work inside an activex webbrowser contol on a form "shellExplorer.2"

I'm just trying to do this natively so I don't want jquery solution.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>JS Bin</title>
  <script type="text/javascript">
    function docode() {    
      console.log(document.activeElement.tagName);
    }
  </script>
</head>
<body onclick="docode();" contentEditable="true">
    <div tabindex=1>Here</div>
    <div>Nothing here</div>
    <div contenteditable>Something here</div>
    <table>
        <tr>
          <td> test text </td> <td> test 2</td>   
        </tr>
    </table>  
  </body>
</html>

I have the above html. Ultimately I need to know which element is clicked on so I can find out if the element is inside a table for example. (my old code worked and I walk up the parentnodes until I hit a table or a body tag.

All I seem to get is "BODY". Sometimes I might be lucky and get a DIV for the div with a tabindex.

I have tried the following function and that just returns "undefined"

    function docode() {    
      var ovar = window.getSelection();
      var orange = ovar.getRangeAt(0);
      console.log(orange.tagname);
    }

The getSelection() and getRangeAt(0) used to work but it seems microsoft have changed something in the control.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda